package com.edu.dao;

import com.edu.entity.Diningcar;
import com.edu.entity.FoodType;
import com.edu.utils.JdbcHelper;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author ZCN
 * @Date 2021/11/12 16:31
 * @Version 1.0
 **/
public class DiningcarDao {
    // 查询所有
    List<Diningcar> findAll() throws SQLException {
        String sql = "select * from diningcar";
        List<Diningcar> list = JdbcHelper.query(sql,Diningcar.class);
        return list;
    }

    // 根据id查询
    Diningcar findOne(Integer id) throws SQLException {
        String sql = "select * from diningcar where id = ?";
        List<Diningcar> list = JdbcHelper.query(sql, Diningcar.class, id);
        return list.get(0);
    }

    // 修改
    void update(Diningcar diningcar) throws SQLException {
        String sql = "update diningcar set userid = ?,foodid = ? where id = ?";
        JdbcHelper.update(sql, diningcar.getUserid(),diningcar.getFoodid());
    }

    // 删除
    void delete(Integer id) throws SQLException {
        String sql = "delete from diningcar where id = ?";
        JdbcHelper.update(sql,id);
    }

    // 添加
    void insert(Diningcar diningcar) throws SQLException {
        String sql = "insert into diningcar(userid,foodid) values(?,?)";
        JdbcHelper.update(sql,diningcar.getUserid(),diningcar.getFoodid());
    }
}
